using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Spikes : MonoBehaviour
{
    private Hurt hurting;

    void Start()
    {
        hurting = Hurt.HurtEnd;
    }

    void Update()
    {
        if (hurting == Hurt.HurtStart)
        {
            InvokeRepeating("Hurting",2,2);
            hurting = Hurt.Hurting;
        }
    }

    private void OnTriggerEnter2D(Collider2D collision)
    {
        if (collision.gameObject.layer ==7)
        {
            hurting = Hurt.HurtStart;
            MsgSignal.Dispatch(EventConst.Hurt, true);
        }
    }

    private void OnTriggerExit2D(Collider2D collision)
    {
        if (collision.gameObject.layer == 7)
        {
            hurting = Hurt.HurtEnd;
            MsgSignal.Dispatch(EventConst.Hurt, false);
            CancelInvoke("Hurting");
        }
       
    }

    private void Hurting()
    {
        MsgSignal.Dispatch(EventConst.Hurt, true);
    }
}

public enum Hurt
{
    HurtStart,
    HurtEnd,
    Hurting
}
